// Copyright (C) 2005 Taylor L. Riché <riche@cs.utexas.edu>
//  
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
// 
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software 
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//
// 	$Id: PPFunction.hh 134 2005-08-13 04:30:59Z richetl $	
//

#ifndef PPFUNCTION_HH
#define PPFUNCTION_HH

#include <list>
#include <map>
#include <string>
#include <tracetools/packet.hh>

#ifdef LEE_BUILD
#include "Event.hh"
#else
#include <lee/Event.hh>
#endif

namespace lee
{

  typedef void PktData;
  class Event;

  struct FuncExit
  {
    int exit;
    PktData * pkt;
  };

  class PPFunction
  {
    std::string name;
  protected:
    std::list<FuncExit *> * exitList;
    std::list<Event *> * eventList;
    virtual void processData(PktData * const pkt) = 0;
  public:
    PPFunction() {}
    PPFunction(std::string s) : name(s), exitList(NULL) {}
    virtual ~PPFunction() {}
    virtual std::pair<std::list<FuncExit *> *, std::list<Event *> * > 
    processDataWrapper(PktData * const pkt) {
      exitList = new std::list<FuncExit *>;
      eventList = new std::list<Event *>;
      this->processData(pkt);
      std::pair<std::list<FuncExit *> *, std::list<Event *> * > p;
      p.first = exitList;
      p.second = eventList;
      return p;
    }
    inline std::string getName() {return name;}
    void drop(PktData * pkt) {
      FuncExit * ex = new FuncExit();
      ex->exit = 0;
      ex->pkt = NULL;
      tt::Packet * fullPkt = static_cast<tt::Packet *>(pkt);
      delete fullPkt;
      exitList->push_back(ex);
    }
  };

}
#endif // PPFUNCTION_H
